﻿// <copyright file="KnownColorPickerViewModel.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2009-06-13</date>
// <summary>OpenWPFChart library.
// KnownColorPicker User Control ViewModel.
// </summary>
// <revision>$Id$</revision>

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Media;

namespace OpenWPFChart.Helpers.ChooseColorDialog
{
	/// <summary>
	/// KnownColorPicker control ViewModel.
	/// </summary>
	class KnownColorPickerViewModel : INotifyPropertyChanged
	{
		/// <summary>
		/// Initializes the <see cref="KnownColorPickerViewModel"/> class.
		/// </summary>
		static KnownColorPickerViewModel()
		{
			baseColors = new List<NamedColor>()
			{
				new NamedColor("Unnamed", Color.FromRgb(240, 240, 240)),
				new NamedColor("Unnamed", Color.FromRgb(255, 255, 128)),
				new NamedColor("Unnamed", Color.FromRgb(128, 255, 128)),
				new NamedColor("Unnamed", Color.FromRgb(0, 255, 128)),
				new NamedColor("Unnamed", Color.FromRgb(128, 255, 255)),
				new NamedColor("Unnamed", Color.FromRgb(0, 128, 255)),
				new NamedColor("Unnamed", Color.FromRgb(255, 128, 192)),
				new NamedColor("Unnamed", Color.FromRgb(255, 128, 255)),
				new NamedColor("Red", Color.FromRgb(255, 0, 0)),
				new NamedColor("Yellow", Color.FromRgb(255, 255, 0)),
				new NamedColor("Unnamed", Color.FromRgb(128, 255, 0)),
				new NamedColor("Unnamed", Color.FromRgb(0, 255, 64)),
				new NamedColor("Aqua", Color.FromRgb(0, 255, 255)),
				new NamedColor("Unnamed", Color.FromRgb(0, 128, 192)),
				new NamedColor("Unnamed", Color.FromRgb(128, 128, 192)),
				new NamedColor("Magenta", Color.FromRgb(255, 0, 255)),
				new NamedColor("Unnamed", Color.FromRgb(128, 64, 64)),
				new NamedColor("Unnamed", Color.FromRgb(255, 64, 64)),
				new NamedColor("Lime", Color.FromRgb(0, 255, 0)),
				new NamedColor("Teal", Color.FromRgb(0, 128, 128)),
				new NamedColor("Unnamed", Color.FromRgb(0, 64, 128)),
				new NamedColor("Unnamed", Color.FromRgb(128, 128, 255)),
				new NamedColor("Unnamed", Color.FromRgb(128, 0, 64)),
				new NamedColor("Unnamed", Color.FromRgb(255, 0, 128)),
				new NamedColor("Maroon", Color.FromRgb(128, 0, 0)),
				new NamedColor("Unnamed", Color.FromRgb(255, 128, 0)),
				new NamedColor("Green", Color.FromRgb(0, 128, 0)),
				new NamedColor("Unnamed", Color.FromRgb(0, 128, 64)),
				new NamedColor("Blue", Color.FromRgb(0, 0, 255)),
				new NamedColor("Unnamed", Color.FromRgb(0, 0, 160)),
				new NamedColor("Purple", Color.FromRgb(128, 0, 128)),
				new NamedColor("Unnamed", Color.FromRgb(128, 0, 255)),
				new NamedColor("Unnamed", Color.FromRgb(64, 0, 0)),
				new NamedColor("Unnamed", Color.FromRgb(128, 64, 0)),
				new NamedColor("Unnamed", Color.FromRgb(0, 64, 0)),
				new NamedColor("Unnamed", Color.FromRgb(0, 64, 64)),
				new NamedColor("Navy", Color.FromRgb(0, 0, 128)),
				new NamedColor("Unnamed", Color.FromRgb(0, 0, 64)),
				new NamedColor("Unnamed", Color.FromRgb(64, 0, 64)),
				new NamedColor("Unnamed", Color.FromRgb(64, 0, 128)),
				new NamedColor("Black", Color.FromRgb(0, 0, 0)),
				new NamedColor("Olive", Color.FromRgb(128, 128, 0)),
				new NamedColor("Unnamed", Color.FromRgb(128, 128, 64)),
				new NamedColor("Gray", Color.FromRgb(128, 128, 128)),
				new NamedColor("Unnamed", Color.FromRgb(64, 128, 128)),
				new NamedColor("Silver", Color.FromRgb(192, 192, 192)),
				new NamedColor("Unnamed", Color.FromRgb(64, 1, 64)),
				new NamedColor("White", Color.FromRgb(255, 255, 255)),
			};

			wellKnownColors = from pi in typeof(Colors).GetProperties()
						  select new NamedColor(pi.Name, (Color)pi.GetValue(null, null));
		}

		Color selectedColor = Colors.Transparent;
		/// <summary>
		/// Gets or sets the color selected.
		/// </summary>
		/// <value>Color value.</value>
		public Color SelectedColor
		{
			get { return selectedColor; }
			set
			{
				if (selectedColor != value)
				{
					selectedColor = value;
					NotifyPropertyChanged("SelectedColor");
				}
			}
		}

		/// <summary>
		/// The Color decorated with a user-readable name to show it in UI.
		/// </summary>
		public struct NamedColor
		{
			public NamedColor(string name, Color color)
				: this()
			{
				Name = name;
				Color = color;
			}
			public string Name { get; set; }
			public Color Color { get; set; }
		}

		static List<NamedColor> baseColors;
		/// <summary>
		/// Gets the BaseColors.
		/// </summary>
		/// <value>BaseColors list.</value>
		public static List<NamedColor> BaseColors
		{
			get { return baseColors; }
		}

		static IEnumerable<NamedColor> wellKnownColors;
		/// <summary>
		/// Gets the WellKnownColors.
		/// </summary>
		/// <value>WellKnownColors sequence.</value>
		public static IEnumerable<NamedColor> WellKnownColors
		{
			get { return wellKnownColors; }
		}

		#region INotifyPropertyChanged Members
		public event PropertyChangedEventHandler PropertyChanged;

		void NotifyPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
		#endregion INotifyPropertyChanged Members
	}
}
